//
//  Base64Util.swift
//  SwiftStudyDemoAll
//
//  Created by BINGO on 2019/5/12.
//  Copyright © 2019 mrlong. All rights reserved.
//

import Foundation
class Base64Util {
    static func imgTo64(filePath:String) -> String{
        //获取图片数据
        let fileUrl = URL(fileURLWithPath: filePath)
        let fileData = try! Data(contentsOf: fileUrl)
        
        //将图片转为base64编码
        let base64 = fileData.base64EncodedString(options: .endLineWithLineFeed)
        return base64
    }
    
    static func base64ToImg(base64Code:String) -> Data?{
        do{
            //获取图片数据imageData
          let imageData = Data(base64Encoded: base64Code)
            
            return imageData
        } catch {
            return nil
        }
    }
}
